@extends('layouts.back_stage')
@section('style')
    @parent
    <style>
        *{margin:0;padding:0;}
        .top{width:100%;height:30px;margin:20px 0 20px 0;}
        .top h3{width:300px;height:30px;line-height:30px;float:left;margin:0;}
        .top .btn-primary{float:right;margin-right:5px;text-align: center;}
        .info{display: inline-block;}
        .btn-success{margin-bottom:7px;width:110px;font-size:14px;}
        .create{width:110px;height:30px;line-height: 30px;text-align: center;background:#3879d9;display:block;color:#fff;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;}
        .look{width:110px;font-size:14px;height:30px;line-height: 30px;text-align: center;background:#23b7e5;color:#fff;display:block;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;}
        .relevance{width:110px;height:30px;font-size:14px;line-height: 30px;text-align: center;background:#7266ba;display:block;color:#fff;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;margin-bottom:7px;}
        a:hover{color: #fff;}

        tr{height: auto;}
        .main{width:400px;height:auto;}
        .main .info{width:400px;}
        .main .info .info_sp{float:left;display: inline-block;width:100px;height:35px;text-align: center;}
        .main ul li{
            float: left;
            width:25%;
            display: inline-block;
        }
    </style>
@endsection
@section('content')
    <div class="container">
        <div class="top">
            <h3>要货申请列表</h3>
            @if($company_id != 1)
                <a class="btn btn-primary" href="/applyForCargo/create">新增要货申请单</a>
            @endif
        </div>
        @if($company_id == 1)
            <table class="table" style="margin-top: 20px;">
                <thead>
                <tr>
                    <th>申请公司名</th><th>申请时间</th><th>要货信息</th><th>备注</th><th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($applyList as $key => $value)
                    <tr>
                        <td style="width:150px">{{$value->company_name}}</td>
                        <td style="width:150px">{{$value->created_at}}</td>
                        <td style="width:400px">
                            <div class="main">
                                <ul>
                                    <li class="charts_head">品牌</li>
                                    <li class="charts_head">款号</li>
                                    <li class="charts_head">颜色</li>
                                    <li class="charts_head">数量/手</li>
                                    @foreach($infos[$key] as $k=>$v)
                                    <li>
                                        <dl>
                                            @foreach($v as $ks=>$vs)
                                                @if($k == 'brand')
                                                    <dd>{{ $brands[$vs] }}</dd>
                                                @else
                                                    <dd>{{ $vs }}</dd>
                                                @endif
                                            @endforeach
                                        </dl>
                                    </li>
                                    @endforeach
                                </ul>
                            </div>
                        </td>
                        <td>{{$value->remark}}</td>
                        <td style="width:125px">
                            @if($value->status == 0)
                                <a class="create" href="/applyForCargo/createCode?id={{$value->id}}">生成最大码</a>
                            @elseif($value->status == 1)
                                <button class="btn btn-success" disabled="true">已生成二维码</button>
                                <a class="relevance" href="/applyForCargo/associate?id={{$value->id}}">关联大码出仓</a>
                                <a class="look" href="/applyForCargo/check?id={{$value->id}}">查看</a>
                            @elseif($value->status == 2)
                                <button class="btn btn-success" disabled="true" style="background: #ff6e40;border:0;">已关联二维码</button>
                                <button class="btn btn-success shipments" id="{{$value->id}}">发货</button>
                                <a class="look" href="/applyForCargo/check?id={{$value->id}}">查看</a>
                            @elseif($value->status == 3)
                                <button class="btn btn-success" disabled="true">已发货</button>
                                <a class="look" href="/applyForCargo/check?id={{$value->id}}">查看</a>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @else
            <table class="table" style="margin-top: 20px;">
              <thead>
                <tr>
                    <th>申请时间</th><th>要货信息</th><th>备注</th><th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($applyList as $key => $value)
                    <tr>
                        <td style="width:150px">{{$value->created_at}}</td>
                        <td style="width:400px">
                            <div class="main">
                                <div class="info">
                                    <span class="info_sp">品牌</span>
                                    <span class="info_sp">款号</span>
                                    <span class="info_sp">颜色</span>
                                    <span class="info_sp">数量/手</span>
                                </div>
                                <div class="info">
                                    @foreach($infos[$key] as $val)
                                        @foreach($val as $v)
                                            <span class="info_sp">{{$v}}</span>
                                        @endforeach
                                    @endforeach
                                </div>
                            </div>
                        </td>
                        <td>{{$value->remark}}</td>
                        <td><a href="/applyForCargo/create?edit={{$value->id}}">编辑</a></td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endif
        <div style="float: right">{{ $applyList->links() }}</div>
    </div>
    <script>
        $(".shipments").click(function(){
            var id = $(this).attr("id");
            $(".oText").text("确定要发货吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr("abc",id);
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','oDeliver');
        });
        /*点确定*/
        $(document).on('click','#oDeliver',function(){
            $(".oMask").hide();
            $(".oAnim").hide();
            var id=$(this).attr("abc");
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/applyForCargo/deliverGoods',
                data:{
                    id:id
                },
                dataType:'json',
                success:function (data) {
                    if(data.success == true){
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("发货成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        window.location.reload();
                    }
                    else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        });
    </script>
@endsection